﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entity;
using Business.IManager;
using DataAccess.IService;
using DataAccess.Service;
using System.Data;

namespace Business.Manager
{
    public class OrderManager:IOrderManager
   {
        IOrderService orderService = new OrderService();
        INetworkPortService portService = new NetworkPortService();
        IUtilityPaymentService paymentService = new UtilityPaymentService();
        IStuCardService studentService = new StuCardService();
        IPaymentItemService itemService = new PaymentItemService();
        public String getOrderId(String paymentType)
        {
            if (paymentType.Equals("水电费"))
            {
                return orderService.selectUtilityOrderId();
            }
            else if (paymentType.Contains("网费"))
            {

                return orderService.selectPortOrderId();
            }
            else if (paymentType.Equals("一卡通"))
            {

                return orderService.selectStuCardOrderId();
            }
            else
            {
                return orderService.selectPaymentOrderId();
            }
        }

        public bool generateOrder(BankPay bankPay, NetworkPort port, List<ProjectOrder> orders, List<OrderDetail> details, string stuId)
        {
            bool result = false;
            String orderId = bankPay.OrderId;
            if (bankPay.MerName.Equals("福建师范大学后勤服务中心"))
            {
                orderService.insertUtilityOrder(bankPay, stuId);
                return paymentService.updateUtilityInfor(Convert.ToInt32(bankPay.GoodsID));
            }
            else if (bankPay.MerName.Equals("福建师范大学网络管理中心"))
            {
                orderService.insertPortOrder(bankPay, stuId);
                return portService.updatePortInfor(port);
            }
            else if (bankPay.MerName.Equals("福建师范大学一卡通服务中心"))
            {
                orderService.insertStuCardOrder(bankPay, stuId);
                return studentService.updateStuCardInfor(bankPay.Amount, stuId);
            }
            else
            {
                foreach (ProjectOrder po in orders)
                {
                    
                    if (orderService.addProjectOrder(bankPay, po))  //插入一条订单
                    {
                        foreach (OrderDetail od in po.OrderDetail)
                        {
                            if (orderService.addProjectDetailOrder(od, orderId))//&&itemService.updateStudentPaymentDetail(od))    //添加一条订单详细并且更新学生个人缴费项详细的信息
                            {
                                result = true;
                            }
                        }
                    }
                }
                    /*同时插入多条*/
                //orderService.insertProjectOrder(bankPay, orders);
                //orderService.insertProjectDetailOrder(details, orders[0].OrderId);

                return result;

            }
        }
        public DataSet getStuCardOrderInfor(String stuId)
        {
            return orderService.selectStuCardOrderInfor(stuId);
        }
        public DataSet getUtilityOrderInfor(String stuId)
        {
            return orderService.selectUtilityOrderInfor(stuId);
        }
        public DataSet getNetworkPortOrderInfor(String stuId)
        {
            return orderService.selectNetworkPortOrderInfor(stuId);
        }
        public DataSet getPaymentProjectInfor(String stuId)
        {
            return orderService.selectPaymentProjectInfor(stuId);
        }
        public DataSet getProjectDetailInfor(String orderId, int stuProjectId)
        {
            return orderService.selectProjectDetailInfor(orderId, stuProjectId);
        }
        public DataSet getTuitionOrderSet()
        {
            return orderService.getTuitionOrderSet();
        }
        public DataSet getTuitionSet()
        {

            return orderService.getTuitionSet();
        }




        public DataSet getTuitionDetailSet(String orderId)
        {
            return orderService.getTuitionDetailSet(orderId);
        }







        public DataSet getTuitionOrderSetByStudentId(string studentId)
        {
            return orderService.getTuitionOrderSetByStudentId(studentId);
        }
        public DataSet getStuCardOrderSetByStudentId(string studentId)
        {
            return orderService.getStuCardOrderSetByStudentId(studentId);
        }
        public DataSet getNetworkOrderSetByStudentId(string studentId)
        {
            return orderService.getNetworkOrderSetByStudentId(studentId);
        }
        public DataSet getUtilityOrderSetByStudentId(string studentId)
        {
            return orderService.getUtilityOrderSetByStudentId(studentId);
        }


        public DataSet getTuitionOrderDetailByOrderId(string orderId)
        {
            return orderService.getTuitionOrderDetailByOrderId(orderId);
        }
           
    }
        
    
}
